package fileAndIO;

import org.junit.Test;

import java.io.*;
import java.nio.charset.StandardCharsets;

// 缓冲流
public class Test4 {
    @Test
    public void test1() throws IOException {
        InputStream inputStream = new FileInputStream("C:\\Users\\83726\\ccc\\aa.txt");
        BufferedInputStream bis = new BufferedInputStream(inputStream);
        byte[] bytes = new byte[1024];
        int len = -1;
        while ((len = bis.read(bytes)) != -1) {
            System.out.print(new String(bytes, 0, len));
        }
        bis.close();
        inputStream.close();
    }

    @Test
    public void test2() throws IOException {
        OutputStream ops = new FileOutputStream("C:\\Users\\83726\\ccc\\aa.txt");
        BufferedOutputStream bos = new BufferedOutputStream(ops);
        bos.write("ccc\n".getBytes(StandardCharsets.UTF_8));
        bos.write("ccc\n".getBytes(StandardCharsets.UTF_8));
        bos.write("ccc\n".getBytes(StandardCharsets.UTF_8));
        bos.close();
        ops.close();
    }


}
